/**
 * 影像和图片管理器
 */
import {Zoomer} from "./zoomer/Zoomer";
import {ShapeManager} from "../../utils/shapeManager/ShapeManager";
import {ShapeDrawer} from "../../utils/shapeDrawer/ShapeDrawer";
import {RangeInfo} from "../../utils/shapeManager/PathInfo";

class ImageAndShapeViewer {
    canvas?: HTMLCanvasElement;
    zoomer: Zoomer;
    currentImage?: HTMLImageElement;
    constructor() {
        this.zoomer = new Zoomer();
    }

    sm?: ShapeManager;
    RedrawImage = () => {
        if (this.currentImage === undefined) {
            return;
        }
        const img = this.currentImage;
        if (this.sm === undefined) {
            this.sm = new ShapeManager();
        }

        this.sm.reset();
        let {width, height} = img;
        let borderRange: RangeInfo = {minX: 0, maxX: width, minY: 0, maxY: height};
        this.sm.SetBorder(borderRange);

        let sd = new ShapeDrawer();
        sd.setCanvas(this.canvas);
        sd.setShape(this.sm);
        sd.setShapeToFullScreen();
        sd.draw();
        sd.drawImage(img);
    }

    Render = (img: HTMLImageElement) => {
        console.log('START TO DRAW');
        this.currentImage = img;
        this.RedrawImage();
    }
}

export {ImageAndShapeViewer};